home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / examples / tk / tk03 < prev    next >
Encoding:
Text File  |  1994-07-27  |  5.6 KB  |  250 lines

  1. #!plserver -f
  2. # Maurice LeBrun                     -*-tcl-*-
  3. # 30 Jun 1994
  4. #
  5. # @> A script illustrating multiple toplevel plframes.
  6. #
  7. # $Id: tk03,v 1.3 1994/07/27 17:45:09 furnish Exp $
  8. #
  9. # $Log: tk03,v $
  10. # Revision 1.3  1994/07/27  17:45:09  furnish
  11. # Elucidate bug in plframe destruction mechanism.
  12. #
  13. # Revision 1.2  1994/07/24  07:42:59  mjl
  14. # Eliminated "destroy ." in favor of "exit".
  15. #
  16. # Revision 1.1  1994/07/01  20:44:23  mjl
  17. # Added to illustrate multiple toplevels containing plframes.
  18. #
  19. ###############################################################################
  20.  
  21. wm title . "tk03"
  22. plstdwin .
  23.  
  24. ###############################################################################
  25. # Set up the menubar and message widgets.
  26.  
  27. frame .menu -relief raised -borderwidth 3
  28.  
  29. button .menu.one -text "One" -command "1 .plw.plwin"
  30. pack append .menu .menu.one {left expand fill}
  31.  
  32. button .menu.two -text "Two" -command "2 .plw.plwin"
  33. pack append .menu .menu.two {left expand fill}
  34.  
  35. button .menu.exit -text "Exit" -command "destroy ." 
  36.  
  37. #"quit 0"
  38.  
  39. pack append .menu .menu.exit {right expand fill}
  40.  
  41. message .msg \
  42.     -font -Adobe-helvetica-medium-r-normal--*-240* -aspect 200 \
  43.      -width 500 -borderwidth 1 \
  44.     -text "TK03: Multiple toplevels with plframes"
  45.  
  46. pack append . \
  47.     .menu {top fillx} \
  48.     .msg {top padx 5 pady 5 fill} 
  49.  
  50. tk_menuBar .menu .menu.one .menu.two .menu.exit
  51.  
  52. ###############################################################################
  53. #
  54. # This creates the plframe "megawidget".  If you just want a bare plframe,
  55. # change "plxframe" to "plframe".
  56.  
  57. plxframe .plw
  58. pack append . .plw {left expand fill}
  59.  
  60. ###############################################################################
  61. # Set up the second toplevel
  62.  
  63. toplevel .1
  64. plstdwin .1
  65.  
  66. ###############################################################################
  67. # Set up the second menubar and message widgets.
  68.  
  69. frame .1.menu -relief raised -borderwidth 3
  70.  
  71. button .1.menu.three -text "Three" -command "plot2 .1.plw.plwin"
  72. pack append .1.menu .1.menu.three {left expand fill}
  73.  
  74. button .1.menu.four -text "Four" -command "plot3 .1.plw.plwin"
  75. pack append .1.menu .1.menu.four {left expand fill}
  76.  
  77. button .1.menu.exit -text "Exit" -command "destroy .1"
  78. pack append .1.menu .1.menu.exit {right expand fill}
  79.  
  80. message .1.msg \
  81.     -font -Adobe-helvetica-medium-r-normal--*-240* -aspect 200 \
  82.      -width 500 -borderwidth 1 \
  83.     -text "TK03: Multiple toplevels with plframes"
  84.  
  85. pack append .1 \
  86.     .1.menu {top fillx} \
  87.     .1.msg {top padx 5 pady 5 fill} 
  88.  
  89. tk_menuBar .1.menu .1.menu.three .1.menu.four
  90.  
  91. ###############################################################################
  92. #
  93. # This creates the plframe "megawidget".  If you just want a bare plframe,
  94. # change "plxframe" to "plframe".
  95.  
  96. plxframe .1.plw
  97. pack append .1 .1.plw {left expand fill}
  98.  
  99. ###############################################################################
  100. # Definitions of procedures used in this script.
  101.  
  102. # Punch eject and hold onto your seat !!!
  103.  
  104. proc quit a {
  105.     exit
  106. }
  107.  
  108. # Utility routine.
  109.  
  110. proc dpos w {
  111.     wm geometry $w +300+300
  112. }
  113.  
  114. proc 1 {w} {
  115.     global xscale yscale xoff yoff
  116.  
  117.     set xscale 6.0
  118.     set yscale 1.0
  119.     set xoff   0.0
  120.     set yoff   0.0
  121.  
  122.     plot1 $w
  123. }
  124.  
  125. proc 2 {w} {
  126.     global xscale yscale xoff yoff
  127.  
  128.     set xscale 1.0
  129.     set yscale 0.0014
  130.     set xoff   0.0
  131.     set yoff   0.0185
  132.  
  133.     $w cmd plsyax 5
  134.  
  135.     plot1 $w
  136. }
  137.  
  138. # This is supposed to work just like the plot1() in x01c.c
  139.  
  140. proc plot1 {w} {
  141.     global xscale yscale xoff yoff
  142.  
  143.     set npts 60
  144.     matrix x f $npts
  145.     matrix y f $npts
  146.  
  147.     for {set i 0} {$i < $npts} {incr i} {
  148.     $x $i = [expr $xoff + $xscale * ($i + 1) / $npts]
  149.     $y $i = [expr $yoff + $yscale * pow([$x $i],2)]
  150.     }
  151.  
  152.     set xmax [$x [expr $npts-1]]
  153.     set ymax [$y [expr $npts-1]]
  154.  
  155.     matrix x1 f 6
  156.     matrix y1 f 6
  157.  
  158.     for {set i 0} {$i < 6} {incr i} {
  159.     set j [expr $i*10+3]
  160.     $x1 $i = [$x $j]
  161.     $y1 $i = [$y $j]
  162.     }
  163.  
  164.     $w cmd plcol 1
  165.     $w cmd plenv $xoff $xmax $yoff $ymax 0 0
  166.     $w cmd plcol 6
  167.     $w cmd pllab "(x)" "(y)" "#frPLplot Example 1 - y=x#u2"
  168.  
  169.     # plot the data points
  170.  
  171.     $w cmd plcol 9
  172.     $w cmd plpoin 6 $x1 $y1 9
  173.  
  174.     # draw the line through the data
  175.  
  176.     $w cmd plcol 4
  177.     $w cmd plline $npts $x $y
  178. }
  179.  
  180. # This is supposed to work just like the plot2() in x01c.c
  181.  
  182. proc plot2 {w} {
  183.     $w cmd plcol 1
  184.     $w cmd plenv -2 10 -.4 1.2 0 1
  185.     $w cmd plcol 2
  186.     $w cmd pllab "(x)" "sin(x)/x" "#frPLplot Example 1 - Sinc Function"
  187.  
  188.     # Fill up the array
  189.  
  190.     matrix x1 f 101
  191.     matrix y1 f 101
  192.  
  193.     for {set i 0} {$i < 101} {incr i} {
  194.     set x [expr ($i - 19.)/6.]
  195.     $x1 $i = $x
  196.     $y1 $i = 1
  197.     if {$x != 0} { $y1 $i = [expr sin($x)/$x] }
  198.     }
  199.  
  200.     $w cmd plcol 3
  201.     $w cmd plline 101 $x1 $y1
  202. }
  203.  
  204. # This is supposed to work just like the plot3() in x01c.c
  205.  
  206. proc plot3 {w} {
  207.  
  208.     $w cmd pladv
  209.     $w cmd plvsta
  210.     $w cmd plwind 0.0 360.0 -1.2 1.2
  211.  
  212. # Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y.
  213.  
  214.     $w cmd plcol 1
  215.     $w cmd plbox "bcnst" 60.0 2 "bcnstv" 0.2 2
  216.  
  217. # Superimpose a dashed line grid, with 1.5 mm marks and spaces. 
  218. # plstyl expects two integer matrices for mark and space!
  219.  
  220.     matrix mark i 1
  221.     matrix space i 1
  222.  
  223.     $mark 0 = 1500
  224.     $space 0 = 1500
  225.     $w cmd plstyl 1 $mark $space
  226.  
  227.     $w cmd plcol 2
  228.     $w cmd plbox "g" 30.0 0 "g" 0.2 0
  229.  
  230.     $mark 0 = 0
  231.     $space 0 = 0
  232.     $w cmd plstyl 0 $mark $space
  233.  
  234.     $w cmd plcol 3
  235.     $w cmd pllab "Angle (degrees)" "sine" "#frPLplot Example 1 - Sine function"
  236.  
  237.     matrix x f 101
  238.     matrix y f 101
  239.  
  240.     for {set i 0} {$i < 101} {incr i} {
  241.     $x $i = [expr 3.6 * $i]
  242.     $y $i = [expr sin([$x $i] * 3.141592654 / 180.0)]
  243.     }
  244.  
  245.     $w cmd plcol 4
  246.     $w cmd plline 101 $x $y
  247. }
  248.  
  249. ###############################################################################
  250.